<!--
 * @Descripttion: 用户手册管理
 * @version: 
 * @Author: 穆宏宇
 * @Date: 2020-10-21 13:33:50
 * @LastEditors: 穆宏宇
 * @LastEditTime: 2020-11-04 17:48:40
-->
<template>
	<div class="handbooks">
		<el-row class="upload-box" v-if="list.length<5">
			<el-upload :action="fileUrl" :headers="fileHeaders" :show-file-list="false" :file-list="fileList"
				:on-success="handleAvatarSuccess" :on-error="handleAvatarError" multiple :limit="10000"
				:before-upload="beforeUpload" :on-exceed="handleExceed" drag>
				<i class="el-icon-upload"></i>
				<div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
				<!-- <div class="el-upload__text">最多能上传5个文件</div> -->
				<!-- <div class="el-upload__tip" slot="tip">
          只能上传jpg/png文件，且不超过500kb
        </div> -->
			</el-upload>
			<el-button @click="doIt()" style="margin-top: 20px;">解析发票</el-button>
			<!-- <el-button @click="doIt()" style="margin-top: 20px;" v-if="show == 1">解析发票</el-button> -->
		</el-row>
	</div>
</template>

<script>
	import fileUpdata from "@/api/file.config";
	import {
		deleteFile
	} from "@/api/common.api"
	import {
		queryFileListByType,
		sortingList
	} from '@/api/admin.api'
	export default {
		data() {
			return {
				fileHeaders: fileUpdata.headers(),
				fileUrl: '/vapi/file/batchUploadFile',
				fileList: [],
				list: [],
				queryParams: {
					pageNum: 1,
					pageSize: 10
				},
				total: 0,
				show:0
			};
		},
		mounted() {
			this.getData()
		},
		methods: {
			// 解析发票
			doIt() {
				var that = this;
				sortingList().then(res => {
					this.$message({
						message: '解析成功',
						type: 'success'
					})
				})
			},
			// 上传成功
			handleAvatarSuccess(res) {
				if (res && res.code === 200) {
					this.$message({
						message: '上传成功',
						type: 'success'
					})
					this.fileList = []
					this.getData()
					this.show = 1;
				}else{
					this.$message({
						message: '上传失败',
						type: 'error'
					})
					this.show = 0;
				}
			},
			//  上传失败
			handleAvatarError(err) {
				this.$message({
					message: '上传失败',
					type: 'warning'
				})
			},
			// 下载
			download(item) {
				window.open(item.url)
			},
			// 查询列表
			getData() {
				// queryFileListByType(10).then(res => {
				// 	this.list = res
				// })
			},
			// 删除
			deleteItem(item) {
				this.$confirm('确定删除文件', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					deleteFile(10, item.id).then(res => {
						this.$message({
							type: 'success',
							message: '删除成功!'
						});
						this.getData()
					})

				});
			}
		},
	};
</script>

<style scoped lang='scss'>
	.handbooks {
		.title {
			margin: 10px 0;
			// font-weight: bold;
			text-align: left;
		}

		.upload-box {
			margin-top: 30px;
			text-align: center;
		}
	}
</style>
